package com.huitone.gddw.service.impl.analysis.longsms;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huitone.gddw.dao.analysis.longsms.ILongSmsRepDao;
import com.huitone.gddw.dao.entity.SendSm;
import com.huitone.gddw.model.support.QueryPage;
import com.huitone.gddw.service.analysis.longsms.ILongSmsRepService;
import com.huitone.gddw.service.dto.analysis.longsms.LongSmsRecDTO;
import com.huitone.gddw.service.dto.analysis.longsms.LongSmsRepDTO;
import com.huitone.gddw.service.system.IRoleService;
import com.huitone.gddw.utils.SysLoginUtil;

/**
 *长短信分析 接口实现类
 * @author chengsiyue
 *
 */
@Service
public class LongSmsRepService implements ILongSmsRepService {

	@Autowired
	private ILongSmsRepDao longSmsRepDao;
	
	@Autowired
	private IRoleService roleService;

	@Override
	public QueryPage<LongSmsRepDTO> selectPage(QueryPage<SendSm> page) {
		Map<String, Object> map = page.getParams();
		map.put("isUnit",roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())?"1":"0");
		map.put("userId", SysLoginUtil.getLoginUserId());

		List<LongSmsRepDTO> result = longSmsRepDao.selectPage(map);
		
		QueryPage<LongSmsRepDTO> queryPage = new QueryPage<LongSmsRepDTO>();
		queryPage.setResult(result);
		return queryPage;
	}

	@Override
	public List<LongSmsRepDTO> getRecord(Map<String, Object> map) {
		map.put("isUnit",roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())?"1":"0");
		map.put("userId", SysLoginUtil.getLoginUserId());
		return longSmsRepDao.getRecord(map);
	}

	@Override
	public QueryPage<LongSmsRecDTO> selectLongSmDetial(QueryPage<SendSm> page) {
		Map<String, Object> map = page.getParams();
		map.put("isUnit",roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())?"1":"0");
		map.put("userId", SysLoginUtil.getLoginUserId());
		map.put("start", (page.getPageNo() - 1) * page.getPageSize()+1);
		map.put("end", (page.getPageNo() - 1) * page.getPageSize() + page.getPageSize());

		List<LongSmsRecDTO> result = longSmsRepDao.selectLongSmDetial(map);
		int totalCount = longSmsRepDao.selectCount(map);
		QueryPage<LongSmsRecDTO> queryPage = new QueryPage<LongSmsRecDTO>();
		queryPage.setResult(result);
		queryPage.setPageNo(page.getPageNo());
		queryPage.setPageSize(page.getPageSize());
		queryPage.setTotalCount(totalCount);
		return queryPage;
	}

	@Override
	public List<LongSmsRecDTO> getRecordDetial(Map<String, Object> map) {
		map.put("isUnit",roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())?"1":"0");
		map.put("userId", SysLoginUtil.getLoginUserId());
		return longSmsRepDao.getRecordDetial(map);
	}

	@Override
	public QueryPage<LongSmsRecDTO> detailPage(QueryPage<?> page) {
		Map<String, Object> map = page.getParams();
		map.put("isUnit",roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())?"1":"0");
		map.put("userId", SysLoginUtil.getLoginUserId());
		
		List<LongSmsRecDTO> result = longSmsRepDao.detailPage(map);
		
		QueryPage<LongSmsRecDTO> queryPage = new QueryPage<LongSmsRecDTO>();
		queryPage.setResult(result);
		
		return queryPage;
	}

}
